package me.zhengjie.minbearwcs.serivce.common;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.minbearwcs.dao.config.inf.HttpConfigDao;
import me.zhengjie.minbearwcs.entity.DTO.response.RespWithObject;
import me.zhengjie.minbearwcs.entity.DTO.transfer.Tuple;
import me.zhengjie.minbearwcs.entity.PO.config.HttpConfig;
import me.zhengjie.minbearwcs.entity.PO.config.WcsParamConfigContentPool;
import me.zhengjie.minbearwcs.utils.HttpConfigContentPool;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Service
@RequiredArgsConstructor
public class MinBearService {

    private final HttpConfigDao httpConfigDao;

    public Tuple<HttpConfig> getTuskHttpConig(){
        HttpConfig httpConfig = httpConfigDao.selectByHttpName(HttpConfigContentPool.TUSK_IP_PORT);
        return Tuple.tuple(httpConfig,true);
    }

    @Transactional
    public Tuple<HttpConfig> updateTuskHttpConig(String httpUrl){
        HttpConfig httpConfig = httpConfigDao.selectByHttpName(HttpConfigContentPool.TUSK_IP_PORT);
        if (httpConfig == null){
            httpConfig = new HttpConfig(null,HttpConfigContentPool.TUSK_IP_PORT,httpUrl);
            httpConfigDao.insert(httpConfig);
        }else {
            httpConfigDao.updateByHttpName(HttpConfigContentPool.TUSK_IP_PORT,httpUrl);
        }
        return Tuple.tuple(null,true);
    }


    public Tuple<HttpConfig> getWmsHttpConig(){
        HttpConfig httpConfig = httpConfigDao.selectByHttpName(HttpConfigContentPool.XIAO_XIONG_WMS_IP_PORT);
        return Tuple.tuple(httpConfig,true);
    }

    @Transactional
    public Tuple<HttpConfig> updateWmsHttpConig(String httpUrl){
        HttpConfig httpConfig = httpConfigDao.selectByHttpName(HttpConfigContentPool.XIAO_XIONG_WMS_IP_PORT);
        if (httpConfig == null){
            httpConfig = new HttpConfig(null,HttpConfigContentPool.XIAO_XIONG_WMS_IP_PORT,httpUrl);
            httpConfigDao.insert(httpConfig);
        }else {
            httpConfigDao.updateByHttpName(HttpConfigContentPool.XIAO_XIONG_WMS_IP_PORT,httpUrl);
        }
        return Tuple.tuple(null,true);
    }

}
